'''
Created on 2011-11-23

@author: latios
'''
import os
import sys

import subprocess

import datetime

def run(system,ntuser,days,disks,outfile):
    starttime = datetime.datetime.today()-datetime.timedelta(days);
    starttime = starttime.strftime('%Y-%m-%d')
    try:
        retcode = subprocess.call(
'cd make && allmake.bat "%(ntuser)s" "%(system)s" %(days)d "..\%(output)s" %(disks)s %(starttime)s'
                % 
                {'ntuser':ntuser,'system':system,'days':days,
                'output':outfile,'disks':disks,'starttime':starttime
                }
                ,
                shell=True)            
        if retcode < 0:
            print >>sys.stderr, "Child was terminated by signal", -retcode
        else:
            print >>sys.stderr, "Child returned", retcode
    except OSError, e:
        print >>sys.stderr, "Execution failed:", e

def main():
    run(r'D:\hive\09 23\system',r"D:\hive\09 23\Users\latios\NTUSER.DAT",
        1,'ej','out.csv')

if __name__=='__main__':
    main()